package com.gitee.cirnochat.common.model.vo.resp;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Schema(name = "分页对象", description = "分页对象")
public class PageVo<T> {
    @Schema(name = "页码", description = "页码")
    private Integer page;
    @Schema(name = "每页数量", description = "每页数量")
    private Integer size;
    @Schema(name = "总页数", description = "总页数")
    private Integer pages;
    @Schema(name = "总数量", description = "总数量")
    private Integer total;
    @Schema(name = "数据", description = "数据")
    private List<T> records;

    public PageVo(IPage<T> iPage) {
        this.page = (int) iPage.getCurrent();
        this.size = (int) iPage.getSize();
        this.pages = (int) iPage.getPages();
        this.total = (int) iPage.getTotal();
        this.records = iPage.getRecords();
    }
}
